home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* This module was written by Bob Hartman */
- /* */
- /* */
- /* BinkleyTerm FTSC Mail Session Routines */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include <time.h>
- #include <string.h>
- #include <io.h>
-
- #ifdef __TURBOC__
- #include <alloc.h>
- #else
- #include <malloc.h>
- #endif
-
- #define WAZOO_SECTION
- #define MATRIX_SECTION
-
- #define isBITBRAIN 0x1b
-
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
- #include "find.h" /*PLF Sat 05-06-1989 00:49:59 */
-
- #define rb_plus "r+b"
-
- static int FTSC_callback (char *);
- static int FTSC_sendmail (void);
- static int FTSC_recvmail (void);
-
- #define NUM_FLAGS 4
-
- void FTSC_sender (wz)
- int wz;
- {
- int j;
- char junkbuff[128];
- long t1, timerset ();
-
- if (!wz)
- {
- status_line ("*Sending mail using FSC001 fallback");
- who_is_he = 0;
- sprintf (junkbuff, "*%s (%u/%u)",
- newnodedes.SystemName,
- remote_net,
- remote_node);
- status_line (junkbuff);
- }
-
- Netmail_Session = 1;
-
- FTSC_sendmail ();
- t1 = timerset (1000);
-
- /* See what the receiver would like us to do */
- while ((!timeup (t1)) && CARRIER)
- {
- if ((j = PEEKBYTE ()) >= 0)
- {
- switch (j)
- {
- case TSYNC:
- CLEAR_INBOUND ();
- if (FTSC_recvmail ())
- goto get_out;
- t1 = timerset (1000);
- break;
-
- case SYN:
- CLEAR_INBOUND ();
- if (on_our_nickel)
- SEA_recvreq ();
- else
- {
- SENDBYTE (CAN);
- status_line ("*Refusing inbound file requests");
- }
- t1 = timerset (1000);
- break;
-
- case ENQ:
- CLEAR_INBOUND ();
- SEA_sendreq ();
- goto get_out;
-
- case NAK:
- case 'C':
- TIMED_READ (0);
- TIMED_READ (1);
- TIMED_READ (1);
- SENDBYTE (EOT);
- t1 = timerset (1000);
- break;
-
- case SUB:
- TIMED_READ (0);
- SENDBYTE (CAN);
- break;
-
- default:
- TIMED_READ (0);
- SENDBYTE (EOT);
- break;
- }
- }
- else
- {
- time_release ();
- }
- }
-
- if (!CARRIER)
- {
- status_line ("!Other end hung up on us <humph>.");
- CLEAR_INBOUND ();
- return;
- }
-
- if (timeup (t1))
- {
- FTSC_recvmail ();
- status_line ("!Tired of waiting for other end.");
- }
-
- get_out:
- t1 = timerset (100);
- while (!timeup (t1))
- time_release ();
- if (!wz)
- status_line ("*End of FSC001 Session");
- }
-
- int FTSC_receiver (wz)
- int wz;
- {
- char fname[64];
- int havemail, done, np;
- unsigned int i, j;
- long t1, t2, timerset ();
- FSCAN *dh; /*PLF Fri 05-05-1989 23:23:57 */
- struct stat buf;
- char *HoldName;
-
-
- if (!wz)
- {
- status_line ("*Receiving mail using FSC001 fallback");
- who_is_he = 1;
- }
-
- Netmail_Session = 1;
-
- CLEAR_INBOUND ();
-
- /* Save the state of pickup for now */
- done = no_pickup;
- no_pickup = 0;
- if (FTSC_recvmail ())
- {
- /* Restore the state of pickup */
- no_pickup = done;
- if (!wz)
- status_line ("*End of FSC001 Session");
- return (1);
- }
-
- /* Restore the state of pickup */
- no_pickup = done;
-
- remote_zone = called_zone;
- remote_net = called_net;
- remote_node = called_node;
-
-
- HoldName = HoldAreaNameMunge(called_zone);
-
- /* Now see if we should send anything back to him */
- sprintf (fname, "%s%04x%04x.?UT", HoldName, remote_net, remote_node);
- dh = opendir(); /*PLF Fri 05-05-1989 23:24:21 */
- havemail = findfirst(fname, _A_NORMAL, dh); /*PLF Fri 05-05-1989 23:24:43 */
-
- if (havemail)
- {
- sprintf (fname, "%s%04x%04x.?LO", HoldName, remote_net, remote_node);
- havemail = findfirst(fname, _A_NORMAL, dh); /*PLF Fri 05-05-1989 23:26:49 */
- }
-
- if (havemail)
- {
- for (np = 0; np <= ALIAS_CNT; np++)
- {
- if (alias[np].Net == 0)
- break;
- sprintf (fname, "%s%04x%04x.REQ", CurrentNetFiles, alias[np].Net, alias[np].Node);
- if (!(havemail = findfirst(fname, _A_NORMAL, dh))) /*PLF Fri 05-05-1989 23:27:26 */
- break;
- }
- }
- closedir(dh); /*PLF Fri 05-05-1989 23:29:21 */
- if (havemail)
- {
- status_line ("*No mail waiting for %d:%d/%d", remote_zone, remote_net, remote_node);
- }
- else
- {
- status_line ("*Giving mail to %d:%d/%d", remote_zone, remote_net, remote_node);
- /* Send the TSYNC's until we get a C or NAK or CAN back */
- t1 = timerset (3000); /* set 30 second timeout */
- j = 0xffff;
- done = 0;
- while (!timeup (t1) && CARRIER && !done) /* till then or CD lost */
- {
- SENDBYTE (TSYNC);
-
- t2 = timerset (300);
- while (CARRIER && (!timeup (t2)) && !done)
- {
- i = (unsigned) TIMED_READ (0);
-
- switch (i)
- {
- case 'C':
- case 0x00:
- case 0x01:
- if (j == 'C')
- {
- done = 1;
- FTSC_sendmail ();
- }
- break;
-
- case 0xfe:
- if (j == 0x01)
- {
- done = 1;
- FTSC_sendmail ();
- }
- break;
-
- case 0xff:
- if (j == 0x00)
- {
- done = 1;
- FTSC_sendmail ();
- }
- else
- {
- time_release ();
- }
- break;
-
- case NAK:
- if (j == NAK)
- {
- done = 1;
- FTSC_sendmail ();
- }
- break;
-
- case CAN:
- case ENQ:
- case SYN:
- done = 1;
- status_line ("*Node %d:%d/%d refused to pickup mail", remote_zone, remote_net, remote_node);
- break;
- }
- if (i != 0xffff)
- j = i;
- }
- }
- }
-
- if (wz)
- return TRUE; /* All done if this is WaZOO */
-
- /* Now see if we want to request anything */
- sprintf (fname, "%s%04x%04x.REQ", HoldName, remote_net, remote_node);
- if (!stat (fname, &buf))
- {
- /* Send the SYN character and wait for an ENQ or CAN */
- t1 = timerset (3000); /* set 30 second timeout */
- done = 0;
- while (!timeup (t1) && CARRIER && !done) /* till then or CD lost */
- {
- SENDBYTE (SYN);
-
- t2 = timerset (300);
- while (CARRIER && (!timeup (t2)) && !done)
- {
- i = TIMED_READ (0);
-
- switch (i)
- {
- case ENQ:
- SEA_sendreq ();
-
- case CAN:
- done = 1;
- break;
-
- case 'C':
- case NAK:
- SENDBYTE (EOT);
- break;
-
- case SUB:
- SENDBYTE (CAN);
- break;
-
- default:
- time_release ();
- }
- }
- }
- }
-
- /* Finally, can he request anything from us */
- if (!no_requests)
- SEA_recvreq ();
-
- status_line ("*End of FSC001 Session");
- return TRUE;
- }
-
- static int FTSC_sendmail ()
- {
- FILE *fp;
- char fname[80];
- char s[80];
- char *sptr;
- char *HoldName;
- int c;
- int j = 0;
- struct stat buf;
- struct _pkthdr *tmppkt;
- long t1, time (), timerset ();
- struct tm *tm1, *localtime ();
-
- sptr = s;
- /*--------------------------------------------------------------------*/
- /* Send all waiting ?UT files (mail packets) */
- /*--------------------------------------------------------------------*/
- *ext_flags = 'O';
- HoldName = HoldAreaNameMunge(called_zone);
- for (c = 0; c < NUM_FLAGS; c++)
- {
- #ifndef JACK_DECKER
- if (caller && (ext_flags[c] == 'H'))
- continue;
- #endif
-
- sprintf (fname,
- "%s%04x%04x.%cUT",
- HoldName, called_net, called_node, ext_flags[c]);
- errno = 0;
-
- if (!stat (fname, &buf))
- break;
- } /* for */
-
- /*--- Build a dummy PKT file name */
- invent_pkt_name (s);
-
- status_line (" Sending Mail Packet to %d:%d/%d", called_zone, called_net, called_node);
-
- if (c == NUM_FLAGS)
- {
- sprintf (fname,
- "%s%04x%04x.OUT",
- HoldName, called_net, called_node);
- errno = 0;
- fp = fopen (fname, "wb");
- if (got_error (OPEN_msg, fname))
- {
- return (1);
- }
- errno = 0;
- t1 = time (NULL);
- tm1 = localtime (&t1);
-
- tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
- if (tmppkt == NULL)
- {
- status_line ("!Mem err in sending");
- fclose (fp);
- return (1);
- }
- tmppkt->orig_node = alias[assumed].Node;
- tmppkt->dest_node = called_node;
- tmppkt->year = tm1->tm_year;
- tmppkt->month = tm1->tm_mon;
- tmppkt->day = tm1->tm_mday;
- tmppkt->hour = tm1->tm_hour;
- tmppkt->minute = tm1->tm_min;
- tmppkt->second = tm1->tm_sec;
- tmppkt->rate = 0;
- tmppkt->ver = PKTVER;
- tmppkt->orig_net = alias[assumed].Net;
- tmppkt->dest_net = called_net;
- tmppkt->product = isBITBRAIN;
- if (n_getpassword (called_zone, called_net, called_node))
- {
- if (remote_password != NULL)
- {
- strncpy (tmppkt->password, remote_password, 6);
- strupr (tmppkt->password);
- }
- }
- tmppkt->orig_zone = alias[assumed].Zone;
- tmppkt->dest_zone = called_zone;
-
- fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
- free (tmppkt);
- if (got_error (WRITE_msg, fname))
- {
- fclose (fp);
- return (1);
- }
- fwrite ("\0\0", 2, 1, fp);
- fclose (fp);
- }
- else
- {
- errno = 0;
- fp = fopen (fname, rb_plus);
- if (got_error (OPEN_msg, fname))
- {
- return (1);
- }
- tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
- if (tmppkt == NULL)
- {
- status_line ("!Mem err in sending");
- return (1);
- }
- errno = 0;
- fread (tmppkt, 1, sizeof (struct _pkthdr), fp);
- if (got_error (READ_msg, fname))
- {
- free (tmppkt);
- fclose (fp);
- return (1);
- }
-
- if (n_getpassword (called_zone, called_net, called_node))
- {
- if (remote_password != NULL)
- {
- strncpy (tmppkt->password, remote_password, 8);
- }
- }
-
-
- /* Make sure the zone info is in there */
-
- tmppkt->orig_node = alias[assumed].Node;
- tmppkt->orig_net = alias[assumed].Net;
- tmppkt->orig_zone = alias[assumed].Zone;
- tmppkt->dest_zone = called_zone;
-
- errno = 0;
- fseek (fp, 0L, SEEK_SET);
- fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
- fclose (fp);
- free (tmppkt);
- }
-
- net_problems = send_file (fname, 'S');
- if ((net_problems == TSYNC) || (net_problems == 0))
- {
- if (c == NUM_FLAGS)
- unlink (fname);
- return (net_problems);
- }
-
- /* Delete the sent packet */
- unlink (fname);
-
-
- /*--------------------------------------------------------------------*/
- /* Send files listed in ?LO files (attached files) */
- /*--------------------------------------------------------------------*/
- *ext_flags = 'F';
- status_line (" Outbound file attaches");
-
- if (!do_FLOfile (ext_flags, FTSC_callback))
- return FALSE;
-
-
- /*--------------------------------------------------------------------*/
- /* Send our File requests to other system if it's a WaZOO */
- /*--------------------------------------------------------------------*/
-
- if (requests_ok && remote_capabilities)
- {
- sprintf (fname, request_template, HoldName, called_net, called_node);
- if (!stat (fname, &buf))
- {
- if (!(remote_capabilities & WZ_FREQ))
- status_line ("*F.REQ. declined");
- else
- {
- status_line ("*Making file request");
- if (FTSC_callback (fname))
- unlink (fname);
- }
- }
- }
-
- /*--------------------------------------------------------------------*/
- /* Process WaZOO file requests from other system */
- /*--------------------------------------------------------------------*/
-
- j = respond_to_file_requests (j, FTSC_callback);
-
- /* Now close out the file attaches */
- sent_mail = 1;
- *sptr = 0;
- status_line (" End of outbound file attaches");
- t1 = timerset (100);
- while (CARRIER && !timeup (t1))
- {
- j = TIMED_READ (0);
- if ((j == 'C') || (j == NAK))
- {
- SENDBYTE (EOT);
- t1 = timerset (100);
- }
- else
- {
- time_release ();
- }
- }
- return TRUE;
- }
-
- static int FTSC_recvmail ()
- {
- char fname[80];
- char fname1[80];
- struct _pkthdr tmppkt;
- FILE *fp;
- char *s, *p;
- char done;
- int i;
- int j;
- extern char *receive_file ();
-
- status_line ("*Receiving inbound mail");
-
- if (!CARRIER)
- {
- status_line ("!Other end hung up on us <humph>.");
- CLEAR_INBOUND ();
- return (1);
- }
-
- /* If we don't want to pickup stuff */
- if (no_pickup)
- {
- status_line ("*Pickup is turned off - refusing mail.");
- SENDBYTE (CAN);
- }
- else
- {
- status_line (" Inbound Mail Packet");
- /* Invent a dummy name for the packet */
- invent_pkt_name (fname);
-
- /* Receive the packet with special netmail protocol */
- CLEAR_INBOUND ();
- SENDBYTE ('C');
- SENDBYTE (0x01);
- SENDBYTE (0xfe);
- if ((s = receive_file ((p = CurrentNetFiles), fname, 'B')) != NULL)
- {
- got_packet = 1;
- }
-
- /* Check the password if there is one */
- if ((!remote_capabilities) && (n_getpassword (remote_zone, remote_net, remote_node)))
- {
- if (remote_password != NULL)
- {
- got_packet = 0;
- errno = 0;
- sprintf (fname, "%s%s", p, s);
- fp = fopen (fname, rb_plus);
- if (got_error (OPEN_msg, fname))
- {
- status_line ("!Password Error assumed");
- return (1);
- }
- errno = 0;
- fread (&tmppkt, 1, sizeof (struct _pkthdr), fp);
- if (got_error (OPEN_msg, fname))
- {
- status_line ("!Password Error assumed");
- fclose (fp);
- return (1);
- }
- fclose (fp);
- remote_password[7] = '\0';
- tmppkt.password[7] = '\0';
- if (stricmp (remote_password, tmppkt.password))
- {
- status_line ("!Password Error: expected '%s' got '%s'",
- remote_password, tmppkt.password);
- strcpy (fname1, fname);
- j = strlen (fname) - 3;
- strcpy (&(fname[j]), "Bad");
- if (rename (fname1, fname))
- {
- status_line ("!Mail Packet '%s' cannot be renamed", fname1);
- }
- else
- {
- status_line ("!Mail Packet renamed to '%s'", fname);
- }
- return (1);
- }
- }
- got_packet = 1;
- }
- called_zone = remote_zone;
- called_net = remote_net;
- called_node = remote_node;
- got_mail = got_packet;
-
- done = 0;
- /* Now receive the files if possible */
- status_line (" Inbound file attaches");
- CLEAR_INBOUND ();
- do
- {
- if ((i = try_sealink ()) == 0)
- {
- if (!recvmdm7 (fname))
- {
- done = 1;
- }
- else
- {
- if (!receive_file (CurrentNetFiles, NULL, 'T'))
- {
- if (locate_y > 1 && !(fullscreen && un_attended))
- gotoxy (0, locate_y - 1);
- done = 1;
- }
- else
- {
- got_mail = 1;
- }
- }
- }
- else if (i == 1)
- {
- if (!receive_file (CurrentNetFiles, NULL, 'F'))
- {
- if (locate_y > 1 && !(fullscreen && un_attended))
- gotoxy (0, locate_y - 1);
- done = 1;
- }
- else
- {
- got_mail = 1;
- }
- }
- else
- {
- done = 1;
- }
- } while (!done && CARRIER);
- }
-
- status_line (" End of inbound file attaches");
- CLEAR_INBOUND ();
- return (0);
- }
-
- static int FTSC_callback (sptr)
- char *sptr;
- {
- int j;
- char p;
-
- j = xfermdm7 (sptr);
- p = 'T';
- if (!j)
- {
- net_problems = 1;
- return FALSE;
- }
- else if (j == 2)
- p = 'F';
-
- net_problems = send_file (sptr, p);
- if ((net_problems == TSYNC) || !net_problems)
- {
- net_problems = 1;
- return FALSE;
- }
- return TRUE;
- }